package handle

import (
	"AcsGo/internal/domain"
	"AcsGo/internal/model"
)

func HandleReaderInfoBy85(str string) (string, error) {
	readerInfoRequest, err := domain.HandleReaderInfoRequest85(str)
	if err != nil {
		return "", err
	}
	lg.Debugf("HandleReaderInfoRequest85: %v", readerInfoRequest)

	db, err := model.ConnectDB()
	if err != nil {
		return "", err
	}
	var ok, rdbm string
	reader, err := model.GetReaderBySfzh(db, readerInfoRequest.IdCardNo.Value)
	if err != nil {
		ok = "0"
		rdbm = ""
		queryResponse := domain.InitReaderInfoResponse85(ok, rdbm)
		sb, _ := queryResponse.StringFormat()
		lg.Debugf("HandleReaderInfoRequest85 读者找不到: %v", sb)
		return sb, nil
	}

	// 读取读者借阅图书
	ok = "1"
	rdbm = reader.BM
	queryResponse := domain.InitReaderInfoResponse85(ok, rdbm)
	sb, _ := queryResponse.StringFormat()
	lg.Debugf("HandleReaderInfoRequest85 success: %v", sb)
	return sb, nil
}
